Skip to content

chore(tables): remove tables-fractional-ordering feature flag#5503

Merged
TheodoreSpeaks merged 4 commits into
stagingfrom
feat/remove-fractional-index-ff
Jul 8, 2026
Merged

chore(tables): remove tables-fractional-ordering feature flag#5503
TheodoreSpeaks merged 4 commits into
stagingfrom
feat/remove-fractional-index-ff

Conversation

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator

Summary

  • Removed the tables-fractional-ordering feature flag — fractional order_key ordering is now the only path (it was already the production behavior). Dropped the registry entry, the TABLES_FRACTIONAL_ORDERING env var, and the stale isTablesFractionalOrderingEnabled test mock.
  • Deleted the now-dead legacy integer-position machinery in lib/table/rows/ordering.ts (shiftRowsUpFrom, shiftRowsDownAfter, reserveInsertPosition, reserveBatchPositions, compactPositions) and simplified insert/delete/order-by to the single fractional path.
  • Removed the dead positions batch-insert plumbing end-to-end (contract, route, query hook, undo hook, table-grid paste path, copilot user-table tool) — the server already ignored it. Undo restore still places rows exactly via orderKeys.
  • Added .offset() support to the shared database.mock.ts (the fractional insert path always uses it) and reworked two update-row tests that asserted the removed flag-off semantics.
  • Comment-only touch to schema.ts/types.ts/backfill script to drop flag references (no DDL).

Type of Change

  • Refactor / cleanup (dead code + flag removal)

Testing

  • Tested manually
  • 376 affected tests pass (lib/table, app/api/table, copilot table tool, feature-flags)
  • tsc --noEmit clean; bun run lint clean; bun run check:api-validation:strict passed
  • bun run check:migrations origin/staging: no new migrations

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 8, 2026 3:26am

Request Review

@cursor

cursor Bot commented Jul 8, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches core table insert/delete/query and public batch-insert shape (removed positions), but behavior aligns with production fractional ordering; undo still relies on orderKeys.

Overview
Removes the tables-fractional-ordering flag and TABLES_FRACTIONAL_ORDERING env wiring so fractional order_key is the only row-ordering implementation. Legacy integer position shift/reserve/compact paths in ordering.ts are deleted; inserts, deletes, and list/find ordering always use order_key (with position kept as a best-effort append value only).

positions is dropped from batch insert end-to-end (API contract, route, React Query hook, table grid paste/undo snapshots, copilot user-table tool). Undo/redo still restores placement via orderKeys. Comments and tests are updated; the shared DB mock gains .offset() for fractional insert queries.

Reviewed by Cursor Bugbot for commit 8777864. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR removes the tables-fractional-ordering feature flag and all associated legacy integer-position machinery, since fractional order_key ordering was already the production behavior (the flag was always on). The result is a simplified, single-path implementation across insert, delete, and order-by operations.

  • Flag and env var removed from the registry, env.ts, test mocks, and feature-flags tests — all seven code paths that branched on isFeatureEnabled('tables-fractional-ordering') now unconditionally use the fractional path.
  • Dead ordering functions deleted (shiftRowsUpFrom, shiftRowsDownAfter, reserveInsertPosition, reserveBatchPositions, compactPositions) and the positions field stripped end-to-end from the batch insert contract, query hook, undo hook, table-grid paste, and copilot tool.
  • database.mock.ts extended with .offset() support (returned from limitBuilder) so the fractional OFFSET-based orderKeyAtSlot query can resolve in unit tests; two update-row tests rewritten to assert lock acquisition without the removed position-shift setup.

Confidence Score: 5/5

Safe to merge — this is a dead-code removal of a flag that was already fully enabled in production, with no schema changes and no behavioral change in any live code path.

The fractional ordering path was already the sole active path in production; this PR just deletes the branch that was never taken. Lock acquisition in every insert/delete path (acquireRowOrderLock before resolveInsertOrderKey, nextRowPosition, and resolveBatchInsertOrderKeys) is preserved. The type system, API contract, undo hooks, and store types are all updated consistently. The mock extension for .offset() correctly threads through the limitBuilder closure.

No files require special attention. All changed files are consistent and the removal is end-to-end.

Important Files Changed

Filename Overview
apps/sim/lib/table/rows/ordering.ts Removed all legacy integer-position functions (shiftRowsUpFrom, shiftRowsDownAfter, reserveInsertPosition, reserveBatchPositions, compactPositions); simplified resolveInsertByNeighbor to return string instead of { orderKey, position }; resolveBatchInsertOrderKeys and resolveInsertOrderKey now always use the fractional path.
apps/sim/lib/table/rows/service.ts Removed all isFeatureEnabled('tables-fractional-ordering') branches; batchInsertRowsWithTx, queryRows, findRowMatches, and upsertRow now unconditionally use the fractional path. Lock acquisition in upsertRow's insert branch is preserved.
packages/testing/src/mocks/database.mock.ts Added offset mock and limitBuilder so .limit(n).offset(m) chains used by the fractional orderKeyAtSlot query resolve correctly in tests; resetDbChainMock updated to restore both limit and offset implementations.
apps/sim/lib/table/tests/update-row.test.ts Removed flag-off position-shift mock and the two tests that asserted the removed semantics; remaining lock-acquisition tests now expect rejects and confirm pg_advisory_xact_lock ran before the failure.
apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/table-grid.tsx Removed lastRowPosition, createBatchPositions, and all position fields from pushUndoRef calls and undo row arrays; batch create no longer passes positions to batchCreateRef.
apps/sim/lib/api/contracts/tables.ts Removed positions field and its two refinements (length-match and no-duplicates) from batchInsertTableRowsBodySchema; only orderKeys remains.
apps/sim/hooks/use-table-undo.ts Removed positions arrays from all three batchCreateRowsMutation.mutate calls; undo restore now relies solely on orderKeys for exact placement or appends at the end as a fallback.
apps/sim/stores/table/types.ts Removed position: number from both create-row and create-rows undo action types; consistent with table-grid and use-table-undo changes.
apps/sim/lib/core/config/feature-flags.ts Removed the tables-fractional-ordering entry from the FEATURE_FLAGS registry; the registry now only contains mothership-beta and PII-related flags.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Client as Client / UI
    participant Route as API Route
    participant Service as rows/service.ts
    participant Ordering as rows/ordering.ts
    participant DB as PostgreSQL

    Client->>Route: POST /rows (rows, orderKeys?)
    Route->>Service: batchInsertRowsWithTx(data, table)
    Service->>Ordering: acquireRowOrderLock(trx, tableId)
    Ordering->>DB: pg_advisory_xact_lock(hashtextextended(...))
    DB-->>Ordering: lock acquired

    alt orderKeys provided (undo restore)
        Service->>Service: use data.orderKeys directly
    else no orderKeys (new insert)
        Service->>Ordering: resolveBatchInsertOrderKeys(trx, tableId, count)
        Ordering->>DB: SELECT max(order_key) FROM user_table_rows
        DB-->>Ordering: maxKey
        Ordering->>Ordering: nKeysBetween(maxKey, null, count)
        Ordering-->>Service: orderKeys[]
    end

    Service->>DB: nextRowPosition(trx, tableId) → start
    Service->>DB: "INSERT INTO user_table_rows (order_key, position, ...) RETURNING *"
    DB-->>Service: inserted rows
    Service-->>Route: TableRow[]
    Route-->>Client: "{ data: { rows: [...] } }"
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Client as Client / UI
    participant Route as API Route
    participant Service as rows/service.ts
    participant Ordering as rows/ordering.ts
    participant DB as PostgreSQL

    Client->>Route: POST /rows (rows, orderKeys?)
    Route->>Service: batchInsertRowsWithTx(data, table)
    Service->>Ordering: acquireRowOrderLock(trx, tableId)
    Ordering->>DB: pg_advisory_xact_lock(hashtextextended(...))
    DB-->>Ordering: lock acquired

    alt orderKeys provided (undo restore)
        Service->>Service: use data.orderKeys directly
    else no orderKeys (new insert)
        Service->>Ordering: resolveBatchInsertOrderKeys(trx, tableId, count)
        Ordering->>DB: SELECT max(order_key) FROM user_table_rows
        DB-->>Ordering: maxKey
        Ordering->>Ordering: nKeysBetween(maxKey, null, count)
        Ordering-->>Service: orderKeys[]
    end

    Service->>DB: nextRowPosition(trx, tableId) → start
    Service->>DB: "INSERT INTO user_table_rows (order_key, position, ...) RETURNING *"
    DB-->>Service: inserted rows
    Service-->>Route: TableRow[]
    Route-->>Client: "{ data: { rows: [...] } }"
Loading

Reviews (3): Last reviewed commit: "improvement(tables): drop dead position ..." | Re-trigger Greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile review

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile review

@TheodoreSpeaks TheodoreSpeaks merged commit 8c61720 into staging Jul 8, 2026
18 checks passed
@TheodoreSpeaks TheodoreSpeaks deleted the feat/remove-fractional-index-ff branch July 8, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant